const { Op } = require('sequelize')
const sequelize = require('../db')
const productsmodle = require('../modle/products')
const shoppermodel = require('../modle/shopper')
module.exports = {
    async getprodata(data, offset, limit) {
        return productsmodle.findAll({
            where: {
                ...data
            },
            order: sequelize.random(),
            offset: (offset - 1) * limit,
            limit
        })
    },
    async seacha(shiperisd, seachdata, limit, offset) {
        const rudata = await productsmodle.findAll({
            where: {
                shoperid: shiperisd,
                title: {
                    [Op.like]: `%${seachdata}%`
                }
            },
            order: sequelize.random(),
            offset: (offset - 1) * limit,
            limit,
        })
        return rudata
    },
    async getprodatalx(lx, offset, limit, shoperids) {
        return productsmodle.findAll({
            where: {
                shoperid: shoperids,
                lx,
            },
            order: sequelize.random(),
            offset: (offset - 1) * limit,
            limit
        })
    },
    async getprobyid(data) {
        return productsmodle.findOne({
            where: {
                ...data
            }
        })
    },
    async getshopperdata(id) {
        return await shoppermodel.findOne({
            where: {
                id
            }
        })
    }
}